package com.taru.houseapp.service.impl;


import com.taru.houseapp.dao.IDynamicDao;
import com.taru.houseapp.entity.*;
import com.taru.houseapp.service.IDynamicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class DynamicServiceImpl implements IDynamicService {

    @Autowired
    IDynamicDao iDynamicDao;
    /**
     * 查询所有动态
     */
    @Override
    public List<Dynamic> queryDynamic() {
        List<Dynamic> dynamics= iDynamicDao.queryDynamic();
        return dynamics;
    }
    /**
     * 发布动态圈
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addDynamic(Dynamic dynamic) {
        iDynamicDao.addDynamic(dynamic);
        if(dynamic.getImageList() !=null && dynamic.getImageList().size()>0){
            iDynamicDao.dynamicImage(dynamic);
        }
    }

    /**
     * 删除动态
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void decletedDynamic(List<Integer> ids) {
        iDynamicDao.decletedDynamic(ids);
        iDynamicDao.deleteDynamicImage(ids);
        iDynamicDao.decletedDynaCom(ids);
    }
    /**
     * 查询我发布的动态圈
     */
    @Override
    public List<Dynamic> queryMyDynamic(String userId) {
        List<Dynamic> dynamics= iDynamicDao.queryMyDynamic(userId);
        return dynamics;
    }
    /**
     * 查询动态圈的评论
     */
    @Override
    public List<DynaComment> queryDynaComment(String id) {
        return iDynamicDao.queryDynaComment(id);
    }
    /**
     * 查询给动态圈点赞的人
     */
    @Override
    public List<User> whoLikeDynamic(String id) { return iDynamicDao.whoLikeDynamic(id);
    }

    /**
     * 删除动态评论
     */
    @Override
    public void decletedDynaCom(List<Integer> ids) {
        iDynamicDao.decletedDynaCom(ids);
    }
    /**
     * 添加动态评论
     */
    @Override
    public void addDynamicCom(DynaComment dynaComment) {
        iDynamicDao.addDynamicCom(dynaComment);
    }
    /**
     * 点赞动态
     */
    @Override
    public void likeDynamic(VoDynaLike voDynaLike) {
        iDynamicDao.likeDynamic(voDynaLike);
    }
    /**
     * 取消点赞动态
     */
    @Override
    public void noLikeDynamic(VoDynaLike voDynaLike) {
        iDynamicDao.noLikeDynamic(voDynaLike);
    }
    /**
     * 判断是否点赞该动态
     */
    @Override
    public VoDynaLike whetherLikeDynamic(VoDynaLike voDynaLike) {
        return iDynamicDao.whetherLikeDynamic(voDynaLike);
    }

    @Override
    public List<VoDynaColl> queryUserByCollectionMe(String userId) {

        return iDynamicDao.queryUserByCollectionMe(userId);
    }

    @Override
    public List<VoDynaColl> queryUserByWhoLikeMe(String userId) {

        return iDynamicDao.queryUserByWhoLikeMe(userId);
    }
}
